package br.com.unb.provenance.entities;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.Session;
import org.hibernate.cfg.AnnotationConfiguration;

import br.com.unb.provenance.domain.TypeInstitution;

@Entity
@Table(name = "Institution")
public class Institution {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	private Long id;

	@Column(name = "name")
	private String name;

	@Enumerated(EnumType.STRING)
	@Column(name = "type")
	private TypeInstitution type;

	@ManyToOne(fetch = FetchType.LAZY)
	@NotNull
	@JoinColumn(name = "id_project", nullable = false)		
	private Project project;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public TypeInstitution getType() {
		return type;
	}

	public void setType(TypeInstitution type) {
		this.type = type;
	}

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}
	
	public static void main(String[] args) {
		getSession().createCriteria(Institution.class).list();
	}
	
	public static Session getSession(){
		return new AnnotationConfiguration().configure("hibernate.cfg.xml").buildSessionFactory().openSession();
	}

}
